package logic

import (
	"context"

	domain "go-weixin/app/diary/rpc/internal/doamin"
	"go-weixin/app/diary/rpc/internal/svc"
	"go-weixin/app/diary/rpc/pb/proto/diary"

	"github.com/zeromicro/go-zero/core/logx"
)

type DiaryUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
	diaryDomain *domain.DiaryDomain
}

func NewDiaryUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DiaryUpdateLogic {
	return &DiaryUpdateLogic{
		ctx:         ctx,
		svcCtx:      svcCtx,
		Logger:      logx.WithContext(ctx),
		diaryDomain: domain.NewDiaryDomain(*svcCtx.ChenDb),
	}
}

func (l *DiaryUpdateLogic) DiaryUpdate(in *diary.DiaryUpdateReq) (*diary.DiaryUpdateResp, error) {
	// todo: add your logic here and delete this line
	err := l.diaryDomain.DiaryUpdate(in.Id, in.UserId, in.Title, in.Content)
	if err != nil {
		return nil, err
	}
	return &diary.DiaryUpdateResp{}, nil
}
